package com.hspedu.newData.dmsxl.动态规划.基础;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-04 
 * @Version: 1.0
 */

public class LC53最大子数组和 {

    // todo
    public int maxSubArray(int[] nums) {
        int MAX = nums[0];
        int len = nums.length;
        int[] dp = new int[len];
        dp[0] = MAX;
        for (int i = 1; i < len; i++) {
            dp[i] = Math.max(dp[i-1]+nums[i],nums[i]);
            MAX = Math.max(MAX,dp[i]);
        }
        return MAX;
    }
}
